import 'dart:io';
import 'dart:typed_data';

import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:rebellion_udp/rebellion_udp_common.dart';

import 'rebellion_udp_method_channel.dart';

abstract class RebellionUdpPlatform extends PlatformInterface {
  /// Constructs a RebellionUdpPlatform.
  RebellionUdpPlatform() : super(token: _token);

  static final Object _token = Object();

  static RebellionUdpPlatform _instance = Platform.isIOS ? MethodChannelRebellionUdp(): RebellionUdpCommon();

  /// The default instance of [RebellionUdpPlatform] to use.
  ///
  /// Defaults to [MethodChannelRebellionUdp].
  static RebellionUdpPlatform get instance => _instance;

  /// Platform-specific implementations should set this with their own
  /// platform-specific class that extends [RebellionUdpPlatform] when
  /// they register themselves.
  static set instance(RebellionUdpPlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  Future<String?> getPlatformVersion() {
    throw UnimplementedError('platformVersion() has not been implemented.');
  }

  Future<void> init(String multicastAddress, int port);

  void send(Uint8List data);

  void sendToTarget(String ip, Uint8List data);

  void listen({required Function(Uint8List) read, required Function() write, required Function() closed});

  void close();

  Future<bool?> isOpen();
}
